<template>
	<div class="outer">
    <headers @back-click="back()" :headers="headers"></headers>
		<scroll :topArea="44" ref="authorization" :pullDownRefresh="false" :pullUpLoad="false">
      <div class="auth-content">
        <div class="auth-item">
          <span>商品名称</span>
          <span>{{goods.name}}</span>
        </div>
        <div class="auth-item">
          <span>金额</span>
          <span>￥{{(goods.oriPri/100).toFixed(2)}}</span>
        </div>
        <div class="button-area" @click="showConfirm()">
          <div class="button button-confirm">确定</div>
        </div>
      </div>
  	</scroll>
    <div class="img-area">
      <img src="../../assets/img/lease/zhifubao.png" alt="">
    </div>
	</div>
</template>

<script>
import {checkPriority,goAuthor} from "@/api/homepage.js"
export default {
  name: 'authorization',
  components: {
  },
  data: function(){
  	return {
      headers: {
        title: "授权确认"
      },
      goodParam: "",
      goods: ""
  	}
  },
  methods: {
    back: function(){
      this.$router.go(-1);
    },
    showConfirm: function(){
      let self = this;
      this.$vux.confirm.show({
        content: "正在前往支付宝进行花呗额度冻结，如果没有自动跳转，请点击授权按钮",
        confirmText: "授权",
        onConfirm () {
          goAuthor(self.goodParam).then( data => {
            if(data.code ==200){
               window.location.href = 'https://mapi.alipay.com/gateway.do?' + data.data;
            }else if (data.code == 4031){
                sessionStorage.setItem('desti',window.location.href);
                self.$router.push({name: "personInfo"});
            }else {
                self.$vux.toast.show({
                  text: data.message,
                  time: 1000,
                  width: 'auto',
                  // position: 'middle'
                })
            }
          })
        }
      })
    }
  },
  mounted: function(){
    if(localStorage.goodParam){
      this.goodParam = JSON.parse(localStorage.goodParam);
      this.goods = JSON.parse(localStorage.good);
    }
  },
  // beforeDestroy: function(){
  //   localStorage.removeItem("goodParam");
  // }
}
</script>

<style lang="scss" scoped>
	.outer {
		height: 100%;
    	width: 100%;
    	position: absolute;
	}
.auth-content {
  width: 100%;
  & .auth-item {
    padding: 0 16px;
    background: #fff;
    height: 45px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    &:first-child {
      margin-top: 12px;
    }
    &:not(:last-child){
      border-bottom: 1px solid #eee;
    }
    &>span{
      &:first-child {
        font-size: 14px;
        color: #333;
      }
      &:last-child {
        font-size: 12px;
        color: #999;
      }
    }
  }
  & .button-area {
    height: 36px;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-top: 12px;
    padding: 0 16px;
    &>div {
      width: 100%;
    }
  }
}
.img-area {
  position: absolute;
  left:0;
  right: 0;
  bottom:0;
  display: flex;
  justify-content: center;
  align-items: center;
  &>img {
    width: 120px;
    heigth: 120px;
  }
}
</style>